<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        let obj1 = {name: 'Tom', age: 18}
        let {name: myName, age: myAge} = obj1;
        console.log(myName);
        console.log(myAge);
        // ==========
        // 交换ab的位置 看看效果
        let [b, a] = ['rng', 'tes'];
        // 数组的解构是按照位置对应关系赋值，对象的解构赋值是按照键值对的对应关系进行赋值
        console.log(a);
        console.log(b);
        let {log: log, info: info} = console;
        log(666);
        let {abs: jdz, PI: pai} = Math;
        console.log(pai);
        log(jdz(-3));
        // console 和 Math是对象，本来就有log、info、abs、PI这几个属性和方法，所以可以解构赋值
        // 对象的key和value相同时，可以只保留一个，这是简写

        let person = {
            list: ['eat', 'sleep', 'coding'],
            hobby: {
                eat: ['meat', 'rice', 'hotpot'],
                play: ['lol', 'cf', 'dnf']
            }
        };
        // console.log(person.h1);  对象的解构赋值 要通过key匹配
        let {list, hobby, list: [one, two, three], hobby:{eat, play}} = person;
        console.log(list);
        console.log(hobby);
        console.log(one, two, three);
        console.log(eat, play);
    </script>
</body>
</html>